﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Kkc.Application.Controllers
{
    public class BinaryResult: ActionResult
    {
        private readonly byte[] _output;
        private readonly string _contentType;

        public BinaryResult(byte[] output, string contentType)
        {
            if (output == null)
                throw new ArgumentNullException("output");

            _output = output;
            _contentType = contentType;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = _contentType;
            context.HttpContext.Response.ClearContent();
            context.HttpContext.Response.BinaryWrite(_output);
        }
    }
}
